package com.dede.applib.extends

import android.content.Context
import android.content.SharedPreferences
import org.jetbrains.anko.defaultSharedPreferences

/**
 * @author hsh
 * @time 2017/6/20 020 下午 03:16.
 * @doc
 */
fun Context.getString(key: String, defaultValue: String = ""): String = defaultSharedPreferences.getString(key, defaultValue)

fun Context.getInt(key: String, defaultValue: Int = 0): Int = defaultSharedPreferences.getInt(key, defaultValue)

fun Context.getBoolean(key: String, defaultValue: Boolean = false): Boolean = defaultSharedPreferences.getBoolean(key, defaultValue)

fun Context.clear() = defaultSharedPreferences.clear()

fun Context.putString(key: String, value: String) = defaultSharedPreferences.putString(key, value)

fun Context.putInt(key: String, value: Int) = defaultSharedPreferences.putInt(key, value)

fun Context.putBoolean(key: String, value: Boolean) = defaultSharedPreferences.putBoolean(key, value)

fun Context.remove(key: String) = defaultSharedPreferences.remove(key)


fun SharedPreferences.clear() = this.edit().clear().apply()

fun SharedPreferences.putString(key: String, value: String) = this.edit().putString(key, value).apply()

fun SharedPreferences.putInt(key: String, value: Int) = this.edit().putInt(key, value).apply()

fun SharedPreferences.putBoolean(key: String, value: Boolean) = this.edit().putBoolean(key, value).apply()

fun SharedPreferences.remove(key: String) = this.edit().remove(key).apply()